<template>
  <div class="menu">
    <el-card>
      <div slot="header" class="d-flex align-items-center">
        <img class="card-icon" src="../assets/images/classify.png" />
        <span>{{ $t("carte.carte") }}</span>
      </div>
      <div class="text item">
        <el-menu class="el-menu-vertical-demo" v-for="classify in classifyList" :router="isRouter">
          <div v-if="classify.children.length <= 0">
            <el-menu-item @click="to(classify.identifying)" :index="classify.identifying">
              <span slot="title">{{classify.name}}</span>
            </el-menu-item>
          </div>
          <div v-else>
            <el-submenu :index="classify.identifying">
              <template slot="title">
                <span>{{classify.name}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item @click="to(children.identifying)" :index="children.identifying" v-for="children in classify.children">{{children.name}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </div>
        </el-menu>
      </div>
    </el-card>
  </div>
</template>

<script>
import http from "../api/classify";
export default {
  name: "classify",
  data() {
    return {
      isRouter: false,
      classifyList: [],
    };
  },
  created() {
    this.getClassifyList();
  },
  methods: {
    getClassifyList() {
      http.getClassifyList().then((res) => {
        console.log(res);
        if (res.data.code != 200) {
          this.$message({
            message: "加载分类页数据失败",
            type: "warning",
          });
          return false;
        }
        this.classifyList = res.data.data;
      });
    },
    to(name) {
      this.$router.push({
        name: 'classify',
        params: {
          name: name
        },
        query: {
          type: 'classify'
        }
      })
    }
  },
};
</script>

<style>
.card-icon {
  width: 20px;
  height: 20px;
  margin-right: 10px;
}

.tag-item {
  margin-right: 10px;
}
.el-menu {
  border-right: none;
}
</style>